package com.example.industry.service.impl;

import com.example.industry.util.MyMailSender;
import com.example.industry.dao.ProjectDao;
import com.example.industry.dao.UserDao;
import com.example.industry.entity.User;
import com.example.industry.enums.Roles;
import com.example.industry.service.InviteService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class InviteServiceImpl implements InviteService
{
    @Resource
    private MyMailSender myMailSender;

    @Resource
    private UserDao userDao;

    @Resource
    private ProjectDao projectDao;

    @Override
    public boolean sendInvite(Integer projectId, String email)
    {
        User user = userDao.findByEmail(email);
        String text = "http://localhost:8080/invite/accept?projectId=" + projectId + "&userId=" + user.getUserId();
        myMailSender.sendTextMailMessage(email, "Invite You To Join Our Team.", text + "\n" + "Click the link to join us.Sincerely looking forward to your arrival!");
        return true;
    }

    @Override
    public boolean acceptInvite(Integer projectId, Integer userId)
    {
        return projectDao.addMember(projectId, userId, Roles.COMMON);
    }

}
